<?php
class FrontController
{
	static function main()
	{
		require 'lib/Config.php'; //de configuracion
		require 'lib/SPDO.php'; //PDO con singleton
		require 'lib/ControllerBase.php'; //Clase controlador base
		require 'lib/ModelBase.php'; //Clase modelo base
		require 'lib/View.php'; //Mini motor de plantillas		
		require 'config.php'; //Archivo con configuraciones.
			
		if(! empty($_GET['do']))
		      $controllerName = $_GET['do'] . 'Controller';
		else
		      $controllerName = "IndexController";
	
		if(! empty($_GET['accion']))
		      $actionName = $_GET['accion'];
		else
		      $actionName = "index";
		
		$controllerPath = $config->get('controllersFolder') . $controllerName . '.php';
			
		if(is_file($controllerPath))
		      require $controllerPath;
		else
		      die('El controlador no existe - 404 not found ->'.$controllerPath);
		
		if (is_callable(array($controllerName, $actionName)) == false) 
		{
			trigger_error ($controllerName . '->' . $actionName . '` no existe', E_USER_NOTICE);
			return false;
		}
		$controller = new $controllerName();
                
          if ($_POST OR $_GET){
            $controller->requestVars = $_REQUEST;		
          }
		$controller->$actionName();
	}
}
?>